<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/icon.css">
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>

        //当前选中省份
        var selectRow = null;
		$(function(){
			$("#grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				//width:'auto',
				striped:true,
				rownumbers:true,
			    columns:[[    
			    	{field:'CK',checkbox:true},
			        {field:'company_name',title:'企业编码',width:150,align:'center'}, 
			        {field:'data_source_province',title:'数据源省份',width:100,align:'center'},
                    {field:'data_source_city',title:'数据源城市',width:100,align:'center'},
                    {field:'city_name',title:'精确城市',width:100,align:'center'}
			    ]],
			    pagination:true,
			    pageSize:30,
			    pageList:[10,20,30,50,100,200,500]
			});

            function query(){
				$("#grid").datagrid({
					url:'/manHand/companyArea/getProvinceCityList',
					method:"POST",
					queryParams: parent.getFormJson($("#search_form"))
				});
			}
            //查询按钮
			$("#search_btn").click(query);
            query();

            //下拉框加载数据,
			$('#search_city_code').combobox({    
			    url:'/manHand/companyArea/getComboboxAlreadyCity',    
			    valueField:'code',
			    width:300,
			    textField:'name',
			    filter: function(q, row){
					var opts = $(this).combobox('options');
					return row[opts.textField].indexOf(q) >= 0;
				}
			});

            //修改单条
            $("#edit_btn").click(function(){
                var rows = $('#city_grid').datagrid('getSelections');
                if(rows.length<1){
                    $.messager.alert('提示','请勾选一条');
                    return false;
                }
                $("#city_code").textbox("setValue",rows[0].city_code);
				$("#city_name").textbox("setValue",rows[0].city_name);
				$("#dialog").dialog({ 
                    title: '修改',    
                    width: 800,    
                    height: 220,    
                    closed: false,    
                    cache: false,
                    modal: true,
                    buttons:[{
                        text:'保存',
                        iconCls:'icon-save',
                        handler:function(){
                            $.post("/manHand/area/updateCity",{
                                city_id:selectRow.city_id,
                                city_code:$("#city_code").textbox("getValue"),
                                city_name:$("#city_name").textbox("getValue")
                            },function(response){
                                $("#dialog").dialog('close');
                                $("#city_grid").datagrid('reload');
                            })
                        }
                    }]
                });
			});
           

            //省和地区映射城市
            $("#mapping_btn").click(function(){
				$("#mapping_dialog").dialog({ 
                    title: '映射',    
                    width: 800,    
                    height: 220,    
                    closed: false,    
                    cache: false,
                    //modal: true,
                    buttons:[{
                        text:'保存',
                        iconCls:'icon-save',
                        handler:function(){
                            $.post("/manHand/companyArea/updateCompanyCityFomProvinceAndArea",parent.getFormJson($("#mapping_form")),function(response){
                                alert(response);
                                if(response.indexOf("成功")>0){
                                    $("#mapping_dialog").dialog('close');
                                    $("#grid").datagrid('reload'); 
                                }
                            })
                        }
                    }]
                });
			});


		});
		</script>
	</head>
	<body class="easyui-layout">
		
		<div region="center" border="false" width="50%" >
            <div id ="toolbar">
                <form id ="search_form" method="post" class="easyui-form">
                    <table width="100%">
                        <tr>
                            <td align="right" width="5%">企业名称:</td>
                            <td width="15%"  align="left" >
                                <input class="easyui-textbox"  name="company_name" style="width:500px"  />
                            </td>
                            <td align="right" width="5%">数据源省份:</td>
                            <td width="10%"  align="left" >
                                <input class="easyui-textbox"  name="data_source_province" style="width:200px0"  />
                            </td>
                            <td align="right" width="5%">数据源地区:</td>
                            <td width="10%"  align="left" >
                                <input class="easyui-textbox"  name="data_source_city" style="width:200px"  />
                            </td>
                            <td align="right" width="5%">精确城市:</td>
                            <td width="15%"  align="left">
                                <input class="easyui-combobox" panelHeight='auto' id = "search_city_code"  name="city_code" style="width:200px"  />
                            </td>
                            <td width="15%" ></td>
                        </tr>
                    </table>
                </form>
                <a href="#" id='search_btn' class="easyui-linkbutton" data-options="iconCls:'icon-edit'">查询</a>
                <a href="#" id='edit_btn' class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
                <a href="#" id='mapping_btn' class="easyui-linkbutton" data-options="iconCls:'icon-edit'">批量编辑1(填入省，地区映射城市)</a>
            </div>
			<table id="grid" data-options="toolbar:'#toolbar'">
                
            </table>  
        </div>
        

        <div style="display:none" id="dialog">
            <table width="100%">
                </tr>
                    <td align="right" width="20%">城市编码:</td>
                    <td width="20%"  align="left">
                        <select class="easyui-textbox" id = "city_code"  name="city_code" style="width:400px">
                    </td>
                    <td width="20%" ></td>
                </tr>
                </tr>
                    <td align="right" width="20%">城市名称:</td>
                    <td width="20%"  align="left">
                        <select class="easyui-textbox" id = "city_name"  name="city_name" style="width:400px">
                    </td>
                    <td width="20%" ></td>
                </tr>
            </table> 
        </div>


        <div style="display:none" id="mapping_dialog">
            <form id ="mapping_form" method="post" >   
                <table width="100%">
                    <tr>
                        <td align="right" width="20%">数据源省名称:</td>
                        <td width="20%"  align="left" >
                            <input class="easyui-textbox"  id="mapping_data_source_province"  name="data_source_province" style="width:300px"  />
                        </td>
                    <tr>
                    
                    <tr>
                        <td align="right" width="20%">数据源城市名:</td>
                        <td width="20%"  align="left" >
                            <input class="easyui-textbox"  id="mapping_data_source_city"  name="data_source_city" style="width:300px"  />
                        </td>
                    <tr>
                    </tr>
                        <td align="right" width="20%">映射为城市名:</td>
                        <td width="20%"  align="left">
                            <select class="easyui-textbox"  id="mapping_city_name" name="city_name" panelHeight='auto'  style="width:300px">
                        </td>
                        <td width="20%" ></td>
                    </tr>
                </table> 
            </form>
        </div> 

        


    </body>
</html>
